package com.honry.identityaccess.domain.model.identity;

import java.io.Serializable;

import com.honry.common.AssertionConcern;

public final class ContactInfo extends AssertionConcern implements Serializable {

	private static final long serialVersionUID = 1L;

	private EmailAddress emailAddress;
	private Telephone primaryTelephone;
	private ContactInfo() {
		super();
	}
	public ContactInfo(EmailAddress emailAddress,Telephone primaryTelephone) {
		this();
		this.setEmailAddress(emailAddress);
		this.setPrimaryTelephone(primaryTelephone);
	}
	public ContactInfo(ContactInfo contactInfo){
		
		this(contactInfo.emailAddress(),contactInfo.primaryTelephone());
	}
	public ContactInfo changeEmailAddress(EmailAddress emailAddress) {
        return new ContactInfo(
                emailAddress,
                this.primaryTelephone()
                );
    }
	public ContactInfo changePrimaryTelephone(Telephone telephone) {
        return new ContactInfo(
               this.emailAddress(),
               telephone
              );
    }
	/**
	 * 电子邮件地址
	 * @return
	 */
	public EmailAddress emailAddress(){
		return this.emailAddress;
	}
	private void setEmailAddress(EmailAddress emailAddress){
		this.assertArgumentNotNull(emailAddress, "email不能为空.");
		this.emailAddress=emailAddress;
	}
	/**
	 * 电话号码
	 * @return
	 */
	public Telephone primaryTelephone() {
		return primaryTelephone;
	}
	
	private void setPrimaryTelephone(Telephone primaryTelephone) {
		this.assertArgumentNotNull(primaryTelephone, "电话不能为空.");
		this.primaryTelephone = primaryTelephone;
	}
	@Override
	public boolean equals(Object object){
		boolean equalsObjects=false;
		if(object!=null&&this.getClass()==object.getClass()){
			ContactInfo equalsType=(ContactInfo)object;
			equalsObjects=(
					this.emailAddress.equals(equalsType.emailAddress())&&
					this.primaryTelephone.equals(equalsType.primaryTelephone())
					);
		}
		return equalsObjects;
	}
	@Override
    public int hashCode() {
        int hashCodeValue =
             (73213 * 173)
            + this.emailAddress().hashCode()
            + this.primaryTelephone().hashCode();

        return hashCodeValue;
    }

    @Override
    public String toString() {
        return "ContactInformation [emailAddress=" + this.emailAddress + ", primaryTelephone="
                + this.primaryTelephone + "]";
    }
}
